﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_Notice_Edit : System.Web.UI.Page
{
    public string Content = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        
		/*if (Session["UserID"]==null)
		{
			Response.Write("<script language=javascript>alert('您没有管理权限或者还没有登录，请先登录！');window.open('../login.aspx','_top');</script>");
			Response.End();
		}*/
		
		
		if (!Page.IsPostBack)
        {
            string id = Request.QueryString["id"];
            HiddenID.Value = id;
			showdown();
            if (!string.IsNullOrEmpty(id))
            {
                DataTable dt = Socut.Data.ExecuteDataSet("select title,content,picurl,addtime,bigclassid,smallclassid,hotnews,hotpicnews from web_music where id=" + id).Tables[0];
				if (dt.Rows.Count==1)
				{
					STRtitle.Text = dt.Rows[0]["title"].ToString();
					Pic1.Text = dt.Rows[0]["picurl"].ToString();
					addtime.Text = dt.Rows[0]["addtime"].ToString();
					DropDownList1.Items.FindByValue(dt.Rows[0]["bigclassid"].ToString()+"|"+dt.Rows[0]["smallclassid"].ToString()).Selected=true;
			   }
			   else
			   {
			     	
			   }
            }
			else
			{
			     	addtime.Text=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
			}
			
        }
    }
	
	private void showdown()
	{
		//Response.Write(Session["limitcheck"]);
		//Response.End();
		//string[] strqx = Session["limitcheck"].ToString().Split(',');
		DataTable dt = Socut.Data.ExecuteDataSet("select * from web_music_bigclass order by bigclassorder").Tables[0];
		if(dt.Rows.Count>0)
		{
			for (int i=0;i<dt.Rows.Count;i++)
			{
			   DataTable dts = Socut.Data.ExecuteDataSet("select * from web_music_smallclass where bigclassid=" + dt.Rows[i]["id"] + " order by smallclassorder ").Tables[0];
			   if (dts.Rows.Count>0)
			   {
					for (int j=0;j<dts.Rows.Count;j++)
					{
					  	
						//Response.Write(dts.Rows[j]["id"]);
						//Response.End();
						string strsid=dts.Rows[j]["id"].ToString();
						DropDownList1.Items.Add(new ListItem(dt.Rows[i]["bigclassname"].ToString()+"-"+dts.Rows[j]["smallclassname"].ToString().Replace("&nbsp;"," "),dt.Rows[i]["id"].ToString()+"|"+dts.Rows[j]["id"].ToString()));
					}  
					 
				}
				else
				{
					DropDownList1.Items.Add(new ListItem(dt.Rows[i]["bigclassname"].ToString(),dts.Rows[i]["id"].ToString()+"|"));
				}
			}
		}
	}
	
    protected void Button1_Click(object sender, EventArgs e)
    {
	
	  string s=DropDownList1.SelectedItem.Value;
	  int bigClass=Convert.ToInt32(s.Split('|')[0]);
	  int smallClass=Convert.ToInt32(s.Split('|')[1]);
        string Msg, Url;
        if (string.IsNullOrEmpty(HiddenID.Value))
        {
            Socut.Data.ExecuteNonQuery("insert into web_music (title,picurl,bigclassid,smallclassid,addtime) values ('" + STRtitle.Text + "','" + Pic1.Text + "',"+bigClass+","+smallClass+",'" + addtime.Text + "')");
            Msg = "添加成功！";
            Url = "default.aspx";
        }
        else
        {
            Socut.Data.ExecuteNonQuery("update web_music set title='" + STRtitle.Text + "',picurl='" + Pic1.Text + "',bigclassid='" + bigClass + "',smallclassid=" + smallClass + ",addtime='" + addtime.Text + "' where id=" + HiddenID.Value);
            Msg = "修改成功！";
            Url = "default.aspx";
        }
        CommonFunction.ShowMessage(Msg,Url);
    }
	
			private bool check_class(string[] ksarry, string ksid)
    {
        for (int i = 0; i < ksarry.Length; i++)
        {
            if (ksarry[i] == ksid)
            {
                return true;
            }
        }
        return false;
    }

}
